<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<style>

		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">访客</h1>
			<a class="mui-icon mui-action-menu mui-icon-personadd mui-pull-right" onclick="addVisitor()"></a>
		</header>
		<div id="visitor-vue" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<ul class="mui-table-view">
					<li v-for="v in visitors" class="mui-table-view-cell mui-media">
						<a href="javascript:;">
							<img v-if="v.visitorSex == '男'" class="mui-media-object mui-pull-left" src="../img/user_man_64px_511728_easyicon.net.png">
							<img v-if="v.visitorSex == '女'" class="mui-media-object mui-pull-left" src="../img/user_woman_black_64px_511729_easyicon.net.png">
							<div class="mui-media-body">
								{{ v.visitorName }}
								<div v-if="v.visitorState == '未访'" class="mui-pull-right mui-badge mui-badge-royal">{{v.visitorState}}</div>
								<div v-if="v.visitorState == '己访'" class="mui-pull-right mui-badge mui-badge-primary">{{v.visitorState}}</div>
								<div v-if="v.visitorState == '过期'" class="mui-pull-right mui-badge mui-badge-danger">{{v.visitorState}}</div>
								<p class="mui-ellipsis">
									<label class="mui-pull-left">{{ v.visitorCompany }}</label>
									<label class="mui-pull-right">{{ v.visitorDate }}</label>
								</p>
							</div>
						</a>
					</li>
				</ul>
			</div>

		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/vue.min.js"></script>
		<script>
			var visitorVue = new Vue({
				el: "#visitor-vue",
				data: {
					visitors: []
				},
				methods: {
					loadVisitors: function(size) {
						if(size == 0) {
							this.visitors = [];
						}

						this.visitors.push({
							visitorName: "小乔",
							visitorCompany: "北京同仁堂",
							visitorSex: "女",
							visitorDate: "2018-03-01",
							visitorState: "未访",
							visitorComeDate: ""
						});
						this.visitors.push({
							visitorName: "刘备",
							visitorCompany: "北京第一人民医院",
							visitorSex: "男",
							visitorDate: "2017-01-01",
							visitorState: "己访",
							visitorComeDate: ""
						});
						this.visitors.push({
							visitorName: "关公",
							visitorCompany: "北京人民大学附属医院",
							visitorSex: "男",
							visitorDate: "2017-03-01",
							visitorState: "过期",
							visitorComeDate: ""
						});
					}
				}
			})

			mui.init({
				swipeBack: false,
				pullRefresh: {
					container: '#visitor-vue',
					down: {
						style: 'circle',
						height: 100,
						auto: true,
						contentdown: "下拉可以刷新",
						contentover: "释放立即刷新",
						contentrefresh: "正在刷新...",
						callback: pulldownRefresh
					},
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});

			/**
			 * 下拉刷新具体业务实现
			 */
			function pulldownRefresh() {
				setTimeout(function() {
					visitorVue.loadVisitors(0);
					mui('#visitor-vue').pullRefresh().endPullupToRefresh((false));
					mui('#visitor-vue').pullRefresh().endPulldownToRefresh(); //refresh completed
				}, 1000);
			}
			var count = 0;
			/**
			 * 上拉加载具体业务实现
			 */
			function pullupRefresh() {
				setTimeout(function() {
					mui('#visitor-vue').pullRefresh().endPullupToRefresh((true)); //参数为true代表没有更多数据了。
					visitorVue.loadVisitors(visitorVue.visitors.length);
				}, 1000);
			}

			function addVisitor() {
				mui.openWindow("visitor.html", "visitor.html")
			}
		</script>
	</body>

</html>